'use strict';
// import result from "../../../pages/cashRead/mock/mockDetail.js"
const db = uniCloud.database();
exports.main = async (event, context) => {
  //event为客户端上传的参数
  let result
  console.log("context", context);
  let {
    flag,
    userID,
    cashID
  } = event

  if (flag == 1) {
    let data = await db.collection("zhimuta-collection")
      .where({
        userID,
        cashID
      })
      .limit(3)
      .get()
    // console.log(data);
    if (data.data.length) result = true
    else result = false
  }

  if (flag == 2) {
    result = await db.collection("zhimuta-cash-read")
      .where({
        cashInfoID: cashID
      })
      .get()
  }
  if (flag == 3) {
    result = await db.collection("zhimuta-collection")
      .where({
        userID,
        cashID
      })
      .remove()
  }
  if (flag == 4) {
    result = await db.collection("zhimuta-collection")
      .where({
        cashID
      })
      .update({
        cashID,
        userID
      })
  }
  if (flag == 5) {
    result = await db.collection("zhimuta-finish")
      .where({
        cashID
      })
      .update({
        cashID,
        userID
      })
  }


  //返回数据给客户端
  return result
};